package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppNew;
import com.vf.admin.miaodong.entity.AppSensitive;
import com.vf.admin.miaodong.entity.AppSetup;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * 敏感词
 */
@Repository
public class AfterSensitiveDao extends BaseDao<AppSensitive> {

    /**
     * 详情
     */
    public AppSensitive get(Integer id) {
        if (id==null || id<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_sensitive where id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppSensitive.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppSensitive appSensitive) {
        if (appSensitive!=null && appSensitive.getId() != null && appSensitive.getId() > 0) {
            this.update(appSensitive);
        } else {
            appSensitive.setId(this.add(appSensitive));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id!=null && id > 0) {
            return;
        }
        String sql = "delete  from app_sensitive where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }


    /**
     * 综合查询
     * @param map
     * @param bean
     * @return
     */
    public List<AppSensitive> findList(Map<String, Object> map, SplitPageBean bean) {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT a.* FROM app_sensitive a where 1=1 ");
        if (StringEx.isNotNull(map.get("sensi"))) {
            sbStr.append(" and a.sensi like ? ");
            paramList.add("%" + map.get("sensi") + "%");
        }
        if (!StringEx.isNull(map.get("startdate"))) {
            sbStr.append(" and a.createtime>=? ");
            paramList.add(map.get("startdate"));
        }
        if (!StringEx.isNull(map.get("enddate"))) {
            sbStr.append(" and a.createtime<=? ");
            paramList.add(map.get("enddate"));
        }
        if (!StringEx.isNull(map.get("state"))) {
            sbStr.append(" and a.state=? ");
            paramList.add(map.get("state"));
        }
        sbStr.append(" order by a.createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppSensitive.class, bean);
    }
}
